<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Working with Pages - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.pdf.pages.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.pdf.pages.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.pdf.save.html">Save Changes to PDF Documents</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.pdf.html">Zend_Pdf</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.pdf.drawing.html">Drawing</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.pdf.pages" class="section"><div class="info"><h1 class="title">Working with Pages</h1></div>
    

    <div class="section" id="zend.pdf.pages.creation"><div class="info"><h1 class="title">Page Creation</h1></div>
        

        <p class="para">
            The pages in a <acronym class="acronym">PDF</acronym> document are represented as
            <span class="classname">Zend_Pdf_Page</span> instances in <span class="classname">Zend_Pdf</span>.
        </p>

        <p class="para">
            <acronym class="acronym">PDF</acronym> pages either are loaded from an existing <acronym class="acronym">PDF</acronym>
            or created using the <span class="classname">Zend_Pdf</span> <acronym class="acronym">API</acronym>.
        </p>

        <p class="para">
            New pages can be created by instantiating new <span class="classname">Zend_Pdf_Page</span>
            objects directly or by calling the  <span class="methodname">Zend_Pdf::newPage()</span> method,
            which returns a <span class="classname">Zend_Pdf_Page</span> object.
             <span class="methodname">Zend_Pdf::newPage()</span> creates a page that is already attached to
            a document. Attached pages can&#039;t be used with another <acronym class="acronym">PDF</acronym>
            documents until it&#039;s not cloned. See <a href="zend.pdf.pages.html#zend.pdf.pages.cloning" class="link">Page
            cloning</a> section for the details.
        </p>

        <p class="para">
            The  <span class="methodname">Zend_Pdf::newPage()</span> method and the
            <span class="classname">Zend_Pdf_Page</span> constructor take the same parameters specifying
            page size. They can take either the size of page ($x, $y) in points (1/72 inch) or a
            predefined constant representing a page type:

            <ul class="itemizedlist">
                <li class="listitem"><p class="para">Zend_Pdf_Page::SIZE_A4</p></li>
                <li class="listitem"><p class="para">Zend_Pdf_Page::SIZE_A4_LANDSCAPE</p></li>
                <li class="listitem"><p class="para">Zend_Pdf_Page::SIZE_LETTER</p></li>
                <li class="listitem"><p class="para">Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE</p></li>
            </ul>
        </p>

        <p class="para">
            Document pages are stored in the <var class="varname">$pages</var> public attribute of the
            <span class="classname">Zend_Pdf</span> class. The attribute holds an array of
            <span class="classname">Zend_Pdf_Page</span> objects and completely defines the instances and
            order of pages. This array can be manipulated like any other <acronym class="acronym">PHP</acronym>
            array:
        </p>

        <div class="example" id="zend.pdf.pages.example-1"><div class="info"><p><b>Example #1 PDF document pages management</b></p></div>
            

            <pre class="programlisting brush: php">
...
// Reverse page order
$pdf-&gt;pages = array_reverse($pdf-&gt;pages);
...
// Add new page
$pdf-&gt;pages[] = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
// Add new page
$pdf-&gt;pages[] = $pdf-&gt;newPage(Zend_Pdf_Page::SIZE_A4);

// Remove specified page.
unset($pdf-&gt;pages[$id]);

...
</pre>

        </div>
    </div>

    <div class="section" id="zend.pdf.pages.cloning"><div class="info"><h1 class="title">Page cloning</h1></div>
        

        <p class="para">
            Existing <acronym class="acronym">PDF</acronym> page can be duplicated by creating new
            <span class="classname">Zend_Pdf_Page</span> object with existing page as a parameter:
        </p>

        <div class="example" id="zend.pdf.pages.example-2"><div class="info"><p><b>Example #2 Duplicating existing page</b></p></div>
            

            <pre class="programlisting brush: php">
...
// Store template page in a separate variable
$template = $pdf-&gt;pages[$templatePageIndex];
...
// Add new page
$page1 = new Zend_Pdf_Page($template);
$page1-&gt;drawText(&#039;Some text...&#039;, $x, $y);
$pdf-&gt;pages[] = $page1;
...

// Add another page
$page2 = new Zend_Pdf_Page($template);
$page2-&gt;drawText(&#039;Another text...&#039;, $x, $y);
$pdf-&gt;pages[] = $page2;
...

// Remove source template page from the documents.
unset($pdf-&gt;pages[$templatePageIndex]);

...
</pre>

        </div>

        <p class="para">
            It&#039;s useful if you need several pages to be created using one template.
        </p>

        <div class="caution"><b class="caution">Caution</b>
            <p class="para">
                Important! Duplicated page shares some <acronym class="acronym">PDF</acronym> resources with
                a template page, so it can be used only within the same document as a template page.
                Modified document can be saved as new one.
            </p>
        </div>

        <p class="para">
            <code class="code">clone</code> operator may be used to create page which is not attached to any document.
            It takes more time than duplicating page since it needs to copy all dependent objects
            (used fonts, images and other resources), but it allows to use pages from different source
            documents to create new one:
        </p>

        <div class="example" id="zend.pdf.pages.example-3"><div class="info"><p><b>Example #3 Cloning existing page</b></p></div>
            

            <pre class="programlisting brush: php">
$page1 = clone $pdf1-&gt;pages[$templatePageIndex1];
$page2 = clone $pdf2-&gt;pages[$templatePageIndex2];
$page1-&gt;drawText(&#039;Some text...&#039;, $x, $y);
$page2-&gt;drawText(&#039;Another text...&#039;, $x, $y);
...
$pdf = new Zend_Pdf();
$pdf-&gt;pages[] = $page1;
$pdf-&gt;pages[] = $page2;
</pre>

        </div>

        <p class="para">
            If several template pages are planned to be used as templates then it could be more efficient
            to utilize <span class="classname">Zend_Pdf_Resource_Extractor</span> class which gives an ability
            to share resources between cloned pages - fonts, images, etc. (otherwise new resource copy
            will be created for each cloned page):
        </p>

        <div class="example" id="zend.pdf.pages.example-4"><div class="info"><p><b>Example #4 
                Cloning existing page using <span class="classname">Zend_Pdf_Resource_Extractor</span> class
            </b></p></div>
            

            <pre class="programlisting brush: php">
$extractor = new Zend_Pdf_Resource_Extractor();
....
$page1 = $extractor-&gt;clonePage($pdf-&gt;pages[$templatePageIndex1]);
$page2 = $extractor-&gt;clonePage($pdf-&gt;pages[$templatePageIndex2]);
$page1-&gt;drawText(&#039;Some text...&#039;, $x, $y);
$page2-&gt;drawText(&#039;Another text...&#039;, $x, $y);
...
$pdf = new Zend_Pdf();
$pdf-&gt;pages[] = $page1;
$pdf-&gt;pages[] = $page2;
</pre>

        </div>
    </div>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.pdf.save.html">Save Changes to PDF Documents</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.pdf.html">Zend_Pdf</a></span><br />
                        <span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.pdf.drawing.html">Drawing</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
  <li class="header up"><a href="reference.html">Zend Framework Reference</a></li>
  <li class="header up"><a href="zend.pdf.html">Zend_Pdf</a></li>
  <li><a href="zend.pdf.introduction.html">Introduction</a></li>
  <li><a href="zend.pdf.create.html">Creating and Loading PDF Documents</a></li>
  <li><a href="zend.pdf.save.html">Save Changes to PDF Documents</a></li>
  <li class="active"><a href="zend.pdf.pages.html">Working with Pages</a></li>
  <li><a href="zend.pdf.drawing.html">Drawing</a></li>
  <li><a href="zend.pdf.interactive-features.html">Interactive Features</a></li>
  <li><a href="zend.pdf.info.html">Document Info and Metadata</a></li>
  <li><a href="zend.pdf.usage.html">Zend_Pdf module usage example</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>